package MyLinkedHashMap;

import java.util.HashMap;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ling
 * Date: 2022-09-19
 * Time: 19:54
 */

/**
 * 哈希双向链表
 */
public class MyLinkedHashMap {
    private HashMap<Integer,Node> map;
    private DoubleList list;
    public MyLinkedHashMap (){
        map=new HashMap<>();
        list=new DoubleList();
    }
    public void addLast(int key,int val) {
        Node x=new Node(key,val);
        list.addLast(x);
        map.put(key,x);
    }
    public Node removeFirst() {
        Node d=list.removeFirst();
        int delete=d.key;
        map.remove(delete);
        return d;
    }
    public Node get(int key) {
        return map.get(key);
    }
    public void remove(Node x) {
        list.remove(x);
        map.remove(x);
    }
    public boolean contains(int key) {
        return map.containsKey(key);
    }
    public int size() {
        return list.size();
    }
}
